﻿using Abp.AutoMapper;
using GN.Pay.Core.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Application.GatewayApp.Dto.Output
{
    /// <summary>
    /// 收银台付款申请输出
    /// </summary>
    [AutoMap(typeof(TradePayApply))]
    public class CashiePayApplyOutput : PayApplyOutput
    {
        public CashiePayApplyOutput()
        {
            this.Channels = new List<string>();
            this.BankCardList = new List<BankCardOutput>();
            this.NetWorkBankChannels = new List<CashiePayChannelOutput>();
            this.ThirdPartyChannels = new List<CashiePayChannelOutput>();
        }

        /// <summary>
        /// 获取通道集合
        /// </summary>
        public List<string> Channels { get; set; }

        /// <summary>
        /// 商户名称
        /// </summary>
        public string MerchantName { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        public string AppName { get; set; }

        /// <summary>
        /// 收银台名称
        /// </summary>
        public string CashierName { get; set; }

        /// <summary>
        /// 商户类型
        /// </summary>
        public int MerchantType { get; set; }

        /// <summary>
        /// Logo 路径
        /// </summary>
        public string LogoUrl { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public List<BankCardOutput> BankCardList { get; set; }

        /// <summary>
        /// 是否支持通道
        /// </summary>
        /// <param name="channelNames">通道名称集合</param>
        /// <returns></returns>
        public bool IsSupportChannel(params string[] channelNames)
        {
            if (channelNames == null || channelNames.Length == 0 || Channels == null || Channels.Count == 0)
            {
                return false;
            }
            foreach (var v in channelNames)
            {
                if (v != null && Channels.Contains(v, StringComparer.InvariantCultureIgnoreCase))
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsShowProtocolPay()
        {
            return !string.IsNullOrWhiteSpace(MemberNo)
               && IsSupportChannel("Gyb.ProtocolPay");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsShowNetWorkBankPay()
        {
            return IsSupportChannel("Gyb.WebPay", "Union.WebPay");
        }

        /// <summary>
        /// 网银通道集合
        /// </summary>
        public List<CashiePayChannelOutput> NetWorkBankChannels { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsShowThirdPartyPay()
        {
            return IsSupportChannel("AliPay.Transfer", "WeiXin.QRCode", "YJPay.WebPay");
        }

        /// <summary>
        /// 第三方通道集合
        /// </summary>
        public List<CashiePayChannelOutput> ThirdPartyChannels { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string ProtocolPayTitleClass()
        {
            if (IsShowProtocolPay())
            {
                return "gn_payfor_active";
            }
            return "";
        }

        public string NetWorkBankPayTitleClass()
        {
            if (IsShowProtocolPay())
            {
                return "";
            }
            return "gn_payfor_active";
        }

        public string ThirdPartyPayTitleClass()
        {
            if (IsShowProtocolPay() || IsShowNetWorkBankPay())
            {
                return "";
            }
            return "gn_payfor_active";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string ProtocolPayDisplay()
        {
            if (IsShowProtocolPay())
            {
                return "block";
            }
            return "none";
        }

        public string NetWorkBankPayDisplay()
        {
            if (IsShowProtocolPay())
            {
                return "none";
            }
            return "block";
        }

        public string ThirdPartyPayDisplay()
        {
            if (IsShowProtocolPay() || IsShowNetWorkBankPay())
            {
                return "none";
            }
            return "block";
        }


    }
}
